﻿using System;
using System.Collections.Specialized;

namespace ZhiAo.BaseFramework.DBConnection
{
    public class ConnInfo
    {
        internal static HybridDictionary conn = new HybridDictionary();
        public static ConnectionType DBConnType;
        public static string DBName;
        public static string DBPassWord;
        public static string DBServer;
        public static string DBUser;
        private static string StrConn = "";

        public static string GetConnString()
        {
            if (StrConn != "")
            {
                return StrConn;
            }
            switch (DBConnType)
            {
                case ConnectionType.SQL:
                    return ("Data Source=" + DBServer + ";Initial Catalog=" + DBName + ";User ID=" + DBUser + ";PWD=" + DBPassWord);

                case ConnectionType.OLE:
                    return ("Provider=SQLOLEDB.1;Persist Security Info=False;User ID=" + DBUser + ";PWD=" + DBPassWord + ";Initial Catalog=" + DBName + ";Data Source=" + DBServer);

                case ConnectionType.ORA:
                    return "";
            }
            return "";
        }

        public static void SetConnString(string ConnName, string Conn, ConnectionType type)
        {
            if ((((ConnName != null) && (ConnName != "")) && (Conn != null)) && !(Conn == ""))
            {
                ConnDictInfo info;
                if (conn.Contains(ConnName))
                {
                    info = (ConnDictInfo) conn[ConnName];
                    info.conn = Conn;
                    info.type = type;
                }
                else
                {
                    info = new ConnDictInfo();
                    info.conn = Conn;
                    info.type = type;
                    conn.Add(ConnName, info);
                }
            }
        }

        public static string ConnString
        {
            get
            {
                return GetConnString();
            }
            set
            {
                StrConn = value;
            }
        }

        public static bool IsOracleDB
        {
            get
            {
                return (ConnString.IndexOf("ORA") > 1);
            }
        }
    }
}

